def letter():
    with open('C:\\Users\\ly\Desktop\\sample.txt','r+',encoding='utf-8') as f:
        i = 0
        gw=[]
        data=f.read()
        for line in data:
            if line in "[\+\.\!\/_,$%^*(+\"\']+»|[+——！，_。.,=？、~-@#￥‘%……&*（）1)(+0?123456789\n\t":
                gw.append(' ')
            else:
                gw.append(line)
    word=(''.join(gw)).lower()
    return word.split()
####将txt文档中单词提取出来
def wordcount():
    num=dict()
    for i in letter():
        if i in num.keys():
            num[i]+=1
        else:
            num[i]=1
    #print(num)
    return num
wordcount()
############将出现次数统计并行成字典#########
def lastcount():
    number=sorted(wordcount().items(),key=lambda x:x[1],reverse=True)[:10]
    print(*number)
lastcount()


# 分词这一块，还可以做优化，做得更好一些,总体不做了













